package com.sky.api.client.fallback;

import com.sky.api.client.UserFeignClient;
import com.sky.api.domain.entity.AddressBook;
import com.sky.common.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.web.bind.annotation.RequestParam;

import java.time.LocalDateTime;

/**
 * 用户订单服务降级工厂
 *
 * @author toki
 */
@Slf4j
public class UserFallbackFactory implements FallbackFactory<UserFeignClient> {

    @Override
    public UserFeignClient create(Throwable cause) {
        return new UserFeignClient() {
            @Override
            public Result<Integer> countByMap(@RequestParam LocalDateTime begin,
                                              @RequestParam LocalDateTime end) {
                log.error("用户数据统计失败 : {}", cause.getMessage());
                return Result.success(0);
            }

            @Override
            public Result<AddressBook> getById(Long id) {
                log.error("调用地址簿服务失败，{}", cause.getMessage());
                return Result.success(new AddressBook());
            }
        };
    }
}
